<?php
$this->pageTitle=Yii::app()->name;
?>

<div class="clear"></div>

<div class="box">
    <?php if ( isset($s_errMsg) && banner != '') {?>
    <p><?=$s_errMsg?></p>
    <?php }?>

    <form 
        id     = "form_item"
        name   = "form_item"
        class  = "form_input"
        action = "<?=Yii::app()->createUrl("site/save");?>"
        method = "post"
    >
        <input type="hidden" id="item_key" name="item_key" value="<?php if(isset($o_model)) { echo $o_model->key;} else echo "0"?>">
        <input type="hidden" id="hid_logo" name="hid_logo" value="<?php if(isset($o_model)) { echo $o_model->logo;}?>">
        <input type="hidden" id="hid_logoFooter" name="hid_logoFooter" value="<?php if(isset($o_model)) { echo $o_model->logo_footer;}?>">
        <input type="hidden" id="hid_banner" name="hid_banner" value="<?php if(isset($o_model)) { echo $o_model->banner;}?>">
        
        <fieldset class="border_radius_all">
            <legend></legend>

            <div class="form_input_row text_center">
                <img 
                    alt   = "preview"
                    src   = "<?php if( isset($o_model) && $o_model->logo != '' ) { echo $o_model->logo;}?>"
                    class = "image_preview image_round"
                />
                <br/>

                <input
                    id       = "e_logo"
                    name     = "e_logo"
                    title    = "Hình ảnh đại diện công ty"
                    type     = "file"
                    class    = "form_textbox textbox_css3"
                    accept   = "image/*"
                    tabindex = "2"
                    onchange = "ajaxFileUpload('e_logo');"
                />
            </div>

            <div class="form_input_row">
                <label class="label_title">Tên Cửa Hàng:*</label>

                <div class="input_item">
                    <input
                        id       = "txt_shopName"
                        name     = "txt_shopName"
                        title    = "Tên Cửa Hàng"
                        type     = "text"
                        value    = "<?php if(isset($o_model)) { echo $o_model->shop_name;}?>"
                        tabindex = "1"
                        onblur   = "validation_empty(this,'lbl_shopNameValidation')"
                    />
                    <label
                        id    = "lbl_shopNameValidation" 
                        class = "lable_validation"
                    >Bạn chưa nhập tên cửa hàng.</label>
                </div>
            </div><!--End form_input_row Name-->

            <div class="form_input_row">
                <label class="label_title">Banner Công Ty</label>

                <div class="input_items">
                    <input
                        id       = "e_banner"
                        name     = "e_banner"
                        title    = "Hình ảnh đại diện công ty nhỏ"
                        type     = "file"
                        tabindex = "4"
                        accept   = "image/*"
                        onchange = "ajaxFileUpload('e_banner');"
                    />

                    <div class="clear"></div>
                    <div class="image_preview">
                        <img alt="preview" src="<?php if(isset($o_model)) { echo $o_model->banner;}?>" />
                    </div>
                </div>
            </div><!--End form_input_row-->
            <div class="clear"></div>

            <div class="form_input_row">
                <label class="label_title">Khẩu Hiệu (Slogan):</label>

                <div class="input_item">
                    <input
                        id       = "txt_slogan"
                        name     = "txt_slogan"
                        title    = "Khẩu Hiệu"
                        type     = "text"
                        value    = "<?php if(isset($o_model)) { echo $o_model->slogan;}?>"
                        tabindex = "5"
                    />
                </div>
            </div><!--End form_input_row-->

            <div class="form_input_row">
                <label class="label_title">Tên Công Ty:</label>

                <div class="input_item">
                    <input
                        id       = "txt_companyName"
                        name     = "txt_companyName"
                        title    = "Tên Công Ty"
                        type     = "text"
                        value    = "<?php if(isset($o_model)) { echo $o_model->company_name;}?>"
                        tabindex = "6"
                    />
                </div>
            </div><!--End form_input_row-->

            <div class="form_input_row">
                <label class="label_title">Mã Số Thuế:</label>

                <div class="input_item">
                    <input
                        id       = "txt_taxId"
                        name     = "txt_taxId"
                        title    = "Mã Số Thuế"
                        type     = "text"
                        value    = "<?php if(isset($o_model)) { echo $o_model->tax_id;}?>"
                        tabindex = "7"
                    />
                </div>
            </div><!--End form_input_row-->

            <div class="form_input_row">
                <label class="label_title">Giấy Phép Kinh Doanh:</label>

                <div class="input_item">
                    <input
                        id       = "txt_businessRegiCert"
                        name     = "txt_businessRegiCert"
                        title    = "Giấy Phép Kinh Doanh"
                        type     = "text"
                        value    = "<?php if(isset($o_model)) { echo $o_model->business_regiCert;}?>"
                        tabindex = "8"
                    />
                </div>
            </div><!--End form_input_row-->

            <div class="row_bottom">
                <input
                    title    = "gửi yêu cầu"
                    name     = "btn_save"
                    id       = "btn_save"
                    type     = "submit"
                    value    = "Lưu"
                    tabindex = "9"
                />
            </div><!--End row_bottom-->
        </fieldset>
    </form>
</div><!--End box-->
<script>
/* ==================================================
* @Method:    ajaxFileUpload
* @Describe:  upload image to server
*             images from another server
* @return:    void
* =================================================== */
function ajaxFileUpload(input_name)
{
    $.ajaxFileUpload ({
        url           : "<?=Yii::app()->createUrl("site/UploadImage");?>",
        secureuri     : false,
        fileElementId : input_name,
        dataType      : "json",
        data:{
            id_item       : "id",
            url_image     : "images/image_default",
            fileInputName : input_name
        },
        success: function (data, status)
        {
            if(typeof(data.error) != "undefined")
            {
                alert(data.error);
            }
            else
            {
                var url_image = "<?=Yii::app()->baseUrl;?>/" + data.result;
                $("#"+input_name).next().next(".image_preview").children("img").attr("src", url_image);
                $("#"+input_name).next().next(".image_preview").show();

                if ( input_name == "e_logo" )
                    $("#hid_logo").val(url_image);
                else if ( input_name == "e_logoFooter" )
                    $("#hid_logo").val(url_image);
                else if ( input_name == "e_banner" )
                    $("#hid_banner").val(url_image);
            }
        },
        error: function (data, status, e)
        {
            alert(e);
        }
    });

    return false;
}//end ajaxFileUpload(urlAction)
</script>